package com.enfi.api.configuration;

import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>TODO
 *
 * @author wind
 * @version 1.0
 * @since 2018/12/14
 */
@ConditionalOnProperty(prefix = "spring.mvc.cors", value = "enabled", havingValue = "true")
@Component
@ConfigurationProperties(prefix = "spring.mvc.cors")
@Data
public class CorsConfig {
    private List<CorsDetail> details;
    private Boolean enabled;
    @Data
    public static class CorsDetail {
        private String path = "/*";
        private String[] allowedOrigins=new String[]{"*"};
        private String[] allowedMethods=new String[]{"*"};
        private String[] allowedHeaders=new String[]{"*"};
        private String[] exposedHeaders=new String[]{HttpHeaders.ACCEPT,HttpHeaders.ACCESS_CONTROL_MAX_AGE,HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
        HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,"X-Frame-Options"};
        private Boolean allowCredentials = false;
    }
}
